package com.changgou.order.controller;

import com.changgou.common.constant.StatusCode;
import com.changgou.common.vo.Result;
import com.changgou.order.pojo.ReturnOrderItem;
import com.changgou.order.service.ReturnOrderItemService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/****
 * @Author:www.itheima.com
 * @Description:
 * @Date www.itheima.com
 *****/

@RestController
@RequestMapping("/returnOrderItem")
@CrossOrigin
public class ReturnOrderItemController {

    @Autowired
    private ReturnOrderItemService returnOrderItemService;

    /***
     * ReturnOrderItem分页条件搜索实现
     * @param returnOrderItem: 查询条件
     * @param page:当前页
     * @param size:每页显示多少条
     * @return 查询结果
     */
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo<ReturnOrderItem>> findPage(@RequestBody(required = false)  ReturnOrderItem returnOrderItem, @PathVariable  int page, @PathVariable  int size){
        //调用ReturnOrderItemService实现分页条件查询ReturnOrderItem
        PageInfo<ReturnOrderItem> pageInfo = returnOrderItemService.findPage(returnOrderItem, page, size);
        return new Result<PageInfo<ReturnOrderItem>>("查询成功！", pageInfo);
    }

    /***
     * ReturnOrderItem分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return 查询结果
     */
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo<ReturnOrderItem>> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用ReturnOrderItemService实现分页查询ReturnOrderItem
        PageInfo<ReturnOrderItem> pageInfo = returnOrderItemService.findPage(page, size);
        return new Result<PageInfo<ReturnOrderItem>>("查询成功！", pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param returnOrderItem 查询条件
     * @return 查询结果
     */
    @PostMapping(value = "/search" )
    public Result<List<ReturnOrderItem>> findList(@RequestBody(required = false)  ReturnOrderItem returnOrderItem){
        //调用ReturnOrderItemService实现条件查询ReturnOrderItem
        List<ReturnOrderItem> list = returnOrderItemService.findList(returnOrderItem);
        return new Result<List<ReturnOrderItem>>("查询成功！", list);
    }

    /***
     * 根据ID删除品牌数据
     * @param id 主键
     * @return 查询结果
     */
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable Long id){
        //调用ReturnOrderItemService实现根据主键删除
        returnOrderItemService.delete(id);
        return new Result(true, StatusCode.OK, "删除成功！");
    }

    /***
     * 修改ReturnOrderItem数据
     * @param returnOrderItem 更新对象
     * @return 操作结果
     */
    @PutMapping
    public Result update(@RequestBody  ReturnOrderItem returnOrderItem){
        //调用ReturnOrderItemService实现修改ReturnOrderItem
        returnOrderItemService.update(returnOrderItem);
        return new Result(true, StatusCode.OK, "修改成功！");
    }

    /***
     * 新增ReturnOrderItem数据
     * @param returnOrderItem 新增对象
     * @return 操作结果
     */
    @PostMapping
    public Result add(@RequestBody  ReturnOrderItem returnOrderItem){
        //调用ReturnOrderItemService实现添加ReturnOrderItem
        returnOrderItemService.add(returnOrderItem);
        return new Result(true, StatusCode.OK, "添加成功！");
    }

    /***
     * 根据ID查询ReturnOrderItem数据
     * @param id 主键
     * @return 查询结果
     */
    @GetMapping("/{id}")
    public Result<ReturnOrderItem> findById(@PathVariable Long id){
        //调用ReturnOrderItemService实现根据主键查询ReturnOrderItem
        ReturnOrderItem returnOrderItem = returnOrderItemService.findById(id);
        return new Result<ReturnOrderItem>("查询成功！", returnOrderItem);
    }

    /***
     * 查询ReturnOrderItem全部数据
     * @return 查询结果
     */
    @GetMapping
    public Result<List<ReturnOrderItem>> findAll(){
        //调用ReturnOrderItemService实现查询所有ReturnOrderItem
        List<ReturnOrderItem> list = returnOrderItemService.findAll();
        return new Result<List<ReturnOrderItem>>("查询成功！", list);
    }
}
